Imports System.Xml.Serialization
Imports EdmxEditor.CodeGeneration

Namespace CSDL

    Public Class EntityType
        Inherits XEntityModelElementWithDocumentationBase

        ''' <summary>Initializes an instance of the <see cref="EntityType" /> class.
        ''' This is the default constructor for this class.</summary>
        Public Sub New()
            MyBase.New("EntityType", EdmXmlNamespace)
        End Sub

        ''' <summary>Initializes an instance of the <see cref="EntityType" /> class.</summary>
        ''' <param name="other">An <see cref="System.Xml.Linq.XElement"/> object to copy from.</param>
        Public Sub New(ByVal other As XElement)
            MyBase.New(other)
        End Sub

        Private __NaviagtionProperties As NavigationPropertyBaseCollection
        Private __Properties As EntityPropertyBaseCollection

        <AutoLoad()> _
        <XmlElement("Key")> _
        Public Property Key() As EntityKeyElement
            Get
                Return DirectCast(Me.Element(MyBase.Name.Namespace + "Key"), EdmxEditor.EntityKeyElement)
            End Get
            Set(ByVal value As EntityKeyElement)
                If (DirectCast(value, XElement).Name <> (MyBase.Name.Namespace + "Key")) Then
                    Throw New ArgumentException("Invalid Element")
                End If
                If (Me.Key IsNot Nothing) Then
                    Me.Key.Remove()
                End If
                Me.Add(New EdmxEditor.EntityKeyElement(value))
            End Set
        End Property

        <AutoLoad()> _
        <XmlElement("NavigationProperty", GetType(NavigationProperty))> _
        Public ReadOnly Property NaviagtionProperties() As NavigationPropertyBaseCollection
            Get
                If (__NaviagtionProperties Is Nothing) Then
                    __NaviagtionProperties = New EdmxEditor.NavigationPropertyBaseCollection(Me, MyBase.Name.Namespace, "NavigationProperty")
                End If
                Return __NaviagtionProperties
            End Get
        End Property

        <AutoLoad()> _
        <XmlElement("Property", GetType(EntityProperty))> _
        Public ReadOnly Property Properties() As EntityPropertyBaseCollection
            Get
                If (__Properties Is Nothing) Then
                    __Properties = New EntityPropertyBaseCollection(Me, MyBase.Name.Namespace, "Property")
                End If
                Return __Properties
            End Get
        End Property

        <XmlAttribute()> _
        Public Property BaseType() As String
            Get
                Return Me.@BaseType
            End Get
            Set(ByVal value As String)
                Me.@BaseType = value
            End Set
        End Property

        <XmlAttribute(), _
         System.ComponentModel.DefaultValue(False)> _
        Public Property Abstract() As Boolean
            Get
                Return Me.@Abstract
            End Get
            Set(ByVal value As Boolean)
                Me.@Abstract = value
            End Set
        End Property

        <XmlAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Qualified, [Namespace]:=CodeGenerationXmlNamespace)> _
        Public Property TypeAccess() As PublicOrInternalAccess
            Get
                Return GetEnumValueAttribute(GetType(PublicOrInternalAccess), Me.Attribute(XName.Get("TypeAccess", CodeGenerationXmlNamespace)))
            End Get
            Set(ByVal value As PublicOrInternalAccess)
                If (Me.Attribute(XName.Get("TypeAccess", CodeGenerationXmlNamespace)) Is Nothing) Then
                    Me.Add(New XAttribute(XName.Get("TypeAccess", CodeGenerationXmlNamespace), ""))
                End If
                SetEnumValueAttribute(GetType(PublicOrInternalAccess), Me.Attribute(XName.Get("TypeAccess", CodeGenerationXmlNamespace)), value)
            End Set
        End Property

    End Class

End Namespace